﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SMSSender.Entities.Models;
using SMSSender.Entities.Utils;
using SMSSender.Common;

namespace SMSSender.DAL.Base
{
    public class V_ListPhoneSendSMSDAOBase
    {
        #region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors

        public V_ListPhoneSendSMSDAOBase(string connectionStringName)
		{
			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

        /// <summary>
        /// Selects ListPhoneSendSMS records from the MessageHistory table.
        /// </summary>
        public List<V_ListPhoneSendSMSInfo> SelectListPhoneSendSMS(string RoleKey)
        {
            string comman = "select * from V_ListPhoneSendSMS where RoleKey in ('" + RoleKey + "')";
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.Text, comman))
            {
                List<V_ListPhoneSendSMSInfo> v_ListPhoneSendSMSInfo = new List<V_ListPhoneSendSMSInfo>();
                while (dataReader.Read())
                {
                    v_ListPhoneSendSMSInfo.Add(MakeV_ListPhoneSendSMSInfo(dataReader));
                }

                return v_ListPhoneSendSMSInfo;
            }
        }

		/// <summary>
		/// Creates a new instance of the MessageHistory class and populates it with data from the specified SqlDataReader.
		/// </summary>
        protected virtual V_ListPhoneSendSMSInfo MakeV_ListPhoneSendSMSInfo(SqlDataReader dataReader)
		{
            V_ListPhoneSendSMSInfo v_ListPhoneSendSMSInfo = new V_ListPhoneSendSMSInfo();
            v_ListPhoneSendSMSInfo.IdRole = SqlClientUtility.GetGuid(dataReader, DbConstants.VLISTPHONESENDSMS.IDROLE);
            v_ListPhoneSendSMSInfo.IdPhone = SqlClientUtility.GetString(dataReader, DbConstants.VLISTPHONESENDSMS.IDPHONE);
            v_ListPhoneSendSMSInfo.PhoneNumber = SqlClientUtility.GetString(dataReader, DbConstants.VLISTPHONESENDSMS.PHONENUMBER);
            v_ListPhoneSendSMSInfo.RoleKey = SqlClientUtility.GetString(dataReader, DbConstants.VLISTPHONESENDSMS.ROLEKEY);
            v_ListPhoneSendSMSInfo.RoleName = SqlClientUtility.GetString(dataReader, DbConstants.VLISTPHONESENDSMS.ROLENAME);
            v_ListPhoneSendSMSInfo.Role = SqlClientUtility.GetBoolean(dataReader, DbConstants.VLISTPHONESENDSMS.ROLE);

            return v_ListPhoneSendSMSInfo;
		}

		#endregion
	}
}
